package Jump;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
    请求的转发：
    什么是请求的转发：
    请求的转发是指：服务器收到请求后，从一次资源跳转到另一个资源的操作叫请求转发


 */
public class Servlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求的参数(办理的材料)查看
        System.out.println(request.getParameter("username"));
        //给材料盖一个章，并传递到counter2(柜台二)怎么走
        request.setAttribute("key1","counter1");
        // 问路  counter2(柜台2)怎么走
        //请求转发必须药以 / 斜杆开头，斜杠表示是：http://ip:port/工程名/ 映射到idea代码的web目录
        //getRequestDispatcher().forward(request,response)  要跳转到哪里 调用这个方法
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/counter2");
        //counter2(柜台2)
        requestDispatcher.forward(request,response);
    }
}
